package com.hospitalsystem.service.impl;

import com.hospitalsystem.entity.CheckList;
import com.hospitalsystem.dao.CheckListDao;
import com.hospitalsystem.service.CheckListService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (CheckList)表服务实现类
 *
 * @author makejava
 * @since 2024-12-28 19:31:42
 */
@Service("checkListService")
public class CheckListServiceImpl implements CheckListService {
    @Resource
    private CheckListDao checkListDao;

    /**
     * 通过ID查询单条数据
     *
     * @param  checkId
     * @return 实例对象
     */
    @Override
    public CheckList queryById(String checkId) {
        return this.checkListDao.queryById(checkId);
    }

    /**
     * 分页查询
     *
     * @param checkList 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CheckList> queryByPage(CheckList checkList, PageRequest pageRequest) {
        long total = this.checkListDao.count(checkList);
        return new PageImpl<>(this.checkListDao.queryAllByLimit(checkList, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param checkList 实例对象
     * @return 实例对象
     */
    @Override
    public CheckList insert(CheckList checkList) {
        this.checkListDao.insert(checkList);
        return checkList;
    }

    /**
     * 修改数据
     *
     * @param checkList 实例对象
     * @return 实例对象
     */
    @Override
    public CheckList update(CheckList checkList) {
        this.checkListDao.update(checkList);
        return this.queryById(checkList.getCheckId());
    }

    /**
     * 通过主键删除数据
     *
     * @param  checkId
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String checkId) {
        return this.checkListDao.deleteById(checkId) > 0;
    }
}
